#include "bsp.h"

#include "Log/log.h"




void bsp_init(void)
{
//    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
    
    bsp_at24cxx_init(); // 初始化EEPROM
//		bsp_at24cxx_write_byte(0x00, 0x05);
//		bsp_at24cxx_read_byte(0x00, &read_data);
//    bsp_at24cxx_test(); 
    bsp_lcd_st7789_init();
    bsp_cst816_init(); 
    bsp_aht21_init();   // 初始化AHT21
    bsp_key_init();
    bsp_rtc_init();     // 初始化RTC
    // bsp_lsm303_init(); 
    // bsp_lcd_fill(0,0,LCD_Height, LCD_Width,0xFFFF);
    // bsp_lcd_clear(0xFFFF);
//    bsp_lcd_st7789_refresh_test();
    // bsp_lcd_fill(50,50,100,100,0x0000); 

    // bsp_lcd_fill(0,0,50,50,0xFFFF);

}



#define Adjust 6
// 静态函数，用于微秒级延时
static void __HAL_Delay_us(uint32_t us, uint16_t CLK_MHz )
{
    // 计算延时时间
    uint32_t Delay = us * CLK_MHz / Adjust;
    do
    {
        __NOP();
    } while (Delay --);
}

#define SYSCLK SystemCoreClock / 1000000
void HAL_Delay_us(uint32_t us)
{
    __HAL_Delay_us(us, SYSCLK);
}

void HAL_Delay_ms(uint32_t ms)
{
    uint32_t i = ms;
    do{
        __HAL_Delay_us(1000, SYSCLK);
    }while(i--);
}



